package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IAreaDao;
import com.hy.erp.inventory.pojo.Area;
import com.hy.erp.inventory.pojo.interfaces.IArea;
import com.hy.erp.inventory.service.interfaces.IAreaService;
/**
 * 
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-13；时间：上午09:16:52</li>
 * <li>类型名称：AreaService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@ Name ( "areaService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class AreaService  extends AbstractBusinessService < IArea > implements IAreaService
{

	@ Override
	public boolean addArea (
								IArea area )
	{
		if ( null == area)
		{
			return true ;
		}
		
		else
		{
			System.out
						.println ("ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh") ;


			IAreaDao areaDao =
			                       ( IAreaDao ) this
			                                          .getDao ( IArea.class ) ;
			
		
			return areaDao
			                .persist ( area ) ;
		}
		
	}

	@ Override
	public boolean modifyArea (
								IArea area )
	{


		if ( ( null == area )
		     || ( null == area
		                                .getIdentifier ( ) )
		     || ( area
		                        .getIdentifier ( )
		                        .trim ( )
		                        .length ( ) == 0 ) )
		{
			return true ;
		}
		else
		{
			IAreaDao areaDao =
                ( IAreaDao ) this
                                   .getDao ( IArea.class ) ;

				
			if ( null == area )
			{
				throw new ArchitectureFoundationException  (
				                                            "修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			
			
			return ( areaDao
			                  .merge ( area ) != null ) ;
		}
	
	
	}

	@ Override
	public Integer removeArea (
								String [ ] areaIds )
	{
		if ( ( null == areaIds )
			     || ( areaIds.length == 0 ) )
		{
			return new Integer (
			                     0 ) ;
		}
		else
		{System.out
					.println (areaIds.length+"HHHHHHHHHHHHHH") ;
			

		IAreaDao areaDao =
            ( IAreaDao ) this
                               .getDao ( IArea.class ) ;
			return areaDao
			                .remove ( areaIds ) ;
		}
		
	}

	@ Override
	public String [ ] addArea (
								Object [ ] area )
	{

		if ( null == area)
		{
			return null ;
		}
		
		else
		{

			IAreaDao areaDao =
			                       ( IAreaDao ) this
			                                          .getDao ( IArea.class ) ;
			
		
			Area[] areas=new Area[area.length];
			for(int i=0;i<area.length;i++)
			{
				Area area2=( Area ) area[i];
				areas[i]=area2;
			}
			
			return areaDao
			                .persist ( areas ) ;
		}
		
	
	}

	@ Override
	public List < IArea > getAllArea ( )
	{

		IAreaDao areaDao =
		                       ( IAreaDao ) this
		                                          .getDao ( IArea.class ) ;
		
	
		return areaDao
		                .find ( ) ;
	}

	@ Override
	public String [ ] modifyArea (
									Object [ ] area )
	{


		if ( null == area)
		{
			return null ;
		}
		
		else
		{

			IAreaDao areaDao =
			                       ( IAreaDao ) this
			                                          .getDao ( IArea.class ) ;
			
		
			Area[] areas=new Area[area.length];
			for(int i=0;i<area.length;i++)
			{
				Area area2=( Area ) area[i];
				areas[i]=area2;
			}
			
			return areaDao
			                .merge  ( areas ) ;
		}
		
	
	
	}


}
